home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: HELP!!! -very important-- #3
- Date: Sat, 30 Mar 96 17:57:31 GMT
- Organization: none
- Message-ID: <828208651snz@genesis.demon.co.uk>
- References: <1996Mar21.001800.138165@forest>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <1996Mar21.001800.138165@forest>
- groy@forest.drew.edu "I can't think of a nickname" writes:
-
- >This is the last one (for a while nayway.. ) I promise.. ;)
- >I am trying to write a program that will take in any input.. and count up
- >the numbers of characters... words and lines... it just doesn't want to
- >work... help??
- >
- >#include<stdio.h>
- >#include<ctype.h>
- >
- >int main() {
- > int words = 0; /* number of words */
- > int lines = 0; /* number of lines */
- > int characters = 0; /* number of characters */
- > char input; /* the area of input */
- > int check_letter(char input); /* function that will check characters */
- > int check_lines(char input); /* function that will check lines */
-
- It is a good rule to put all function declarations at file scope (i.e.
- not within other functions). This ebsures that the compiler will validate
- them correctly.
-
- > int whitespace = 1;
- >
- >
- > printf("type in any group of words, lines, characters that you wish");
- > printf("\nthen the computer will display the amount of words, lines");
- > printf("\nand characters (ignoring any white-space) that you may\n");
- > printf("type in. <<press cntrl-d when done>> \n");
- >
- > while ((scanf("%c",&input)) != EOF)
- > {
- > characters += isalnum(input);
-
- Presumably characters here is actually a count of alpha-numeric characters,
- not characters in general.
-
- You problem is that ctype.h functions/macros don't in general return 0 or 1
- they return zero or nonzero. A common implemenation is to use bit masking
- on a lookup table which gives a very strong possibility of not returning
- 1 on a match.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-